package com.daigoudao.util;

import java.util.Date;

/**
 * 序列号生成类
 * 
 * @author zheng
 * 
 */
public class SequenceUtil {

	private static String lastSeq;

	public static void init(String lastSeq) {
		SequenceUtil.lastSeq = lastSeq;
	}

	public static synchronized String getCurSeq() {
		String curSeq = null;
		String curDate = StringUtils.formatDate(new Date(), 
				"yyyyMMddHHmmss");
		String prefix = lastSeq.substring(0, 14);

		if (prefix.equals(curDate)) {
			curSeq = prefix
					+ String.format("%06d",
							Integer.parseInt(lastSeq.substring(14)) + 1);
		} else {
			curSeq = curDate + "000001";
		}
		lastSeq = curSeq;
		return curSeq;
	}
}
